﻿using Senparc.Weixin.MP;
using Senparc.Weixin.MP.AdvancedAPIs;
using Senparc.Weixin.MP.AdvancedAPIs.TemplateMessage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Akso.Weixin.MP.CommonService.Utilities
{
    public class MessagesHelper
    {
        public static void test()
        {
            var uploadResult = Senparc.Weixin.MP.AdvancedAPIs.MediaApi.UploadTemporaryMedia(PublicArgs.AppId, UploadMediaFileType.thumb,
                                                                     Server.GetMapPath("~/Images/Logo.jpg"));
        }
        public static void SendTemplateMessages(string OpenId)
        {
            DateTime dt = DateTime.Now;
            TimeZoneInfo chinaTimezone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time");
            dt = TimeZoneInfo.ConvertTime(dt, TimeZoneInfo.Local, chinaTimezone);

            var message = new
            {
                first = new TemplateDataItem("恭喜你购买成功", "#743A3A"),
                product = new TemplateDataItem("巧克力", "#FF0000"),
                price = new TemplateDataItem("39.8元", "#C4C400"),
                time = new TemplateDataItem(dt.ToString("yyyy-MM-dd H:mm:ss"), "#0000FF"),
                remark = new TemplateDataItem("欢迎再次购买！", "#008000")
            };
            TemplateApi.SendTemplateMessage("wxa61465105c7a79fe", OpenId,
                                            "Exo3fHHi-vDhROgon7t-iUqhl6Looh9_BpMaH8N1UaU",
                                            "http://www.baidu.com", message);

        }
    }
}
